package 结构性模式


/**
 * 将抽象部分与它的实现部分分离，使它们都可以独立地变化
 */

abstract class Car(protected var engine: Engine) {
    abstract fun drive()
}

interface Engine {
    fun start()
}

abstract class RefinedCar(engine: Engine) : Car(engine) {
    override fun drive() {
        engine.start()
        println("Drive " + getBrand() + " car...")
    }

    abstract fun getBrand(): String
}

class BossCar(engine: Engine) : RefinedCar(engine) {
    override fun getBrand(): String {
        return "Boss"
    }

}

/**
 * 汽车=商标+发动机，可单独增加
 */

class HybridEngine : Engine {
    override fun start() {
        println("Start Hybrid Engine...")
    }

}

fun main() {
    BossCar(HybridEngine()).drive()
}